package com.manager.commons;

import java.util.List;

import javax.servlet.jsp.PageContext;

import org.apache.log4j.Logger;
import org.displaytag.decorator.DisplaytagColumnDecorator;
import org.displaytag.exception.DecoratorException;
import org.displaytag.properties.MediaTypeEnum;

import com.manager.commons.basemanage.commons.SelectStaticData;
import com.manager.commons.basemanage.entity.BaseDataList;

/**  
 * TODO 列表中数据字典 处理   *   
 * @author  Alex   
 * @since  jdk1.6   */
public class DictCodeColumnDecorator implements DisplaytagColumnDecorator {
	private static final Logger logger = Logger.getLogger(DictCodeColumnDecorator.class);


	@Override
	public String decorate(Object value, PageContext context, MediaTypeEnum media) throws DecoratorException {
		String dictCode = "";
		try {
			dictCode = (String)context.getAttribute("DICT_CODE");
		}
		catch(Exception ex) {
			logger.debug("数据字典没有配置！");
		}
		List selectList = (List) SelectStaticData.get(dictCode);
        if(selectList == null) return dictCode;
		for (int i = 0;i<selectList.size();i++) {
			//获得对象
			BaseDataList baseDataList = (BaseDataList) selectList.get(i);
			if(String.valueOf(value).equals(baseDataList.getListCode())){
				return baseDataList.getListName();
			}
		}
		return "";
	}

}
